﻿@page "/Po/BuyDetail/BatchEdit"
@using nERP.ViewModel.Po.BuyDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <div style="margin-bottom:10px;"> @WtmBlazor.Localizer["Sys.BatchEditConfirm"]</div>
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
        <BootstrapInput @bind-Value="@Model.LinkedVM.Seq" />
        <Select @bind-Value="@Model.LinkedVM.BuyId" Items="AllBuys" Id="g0ddbf0b4e6824e1e8d4ab2ac711c687b" />
        <Select @bind-Value="@Model.LinkedVM.GoodsId" Items="AllGoodss" Id="g9fe364fc438d412c81cac6d6b47d7006" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.GoodsName" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.GoodsSpec" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.GoodsUnit" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.BuyNumber" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.UnitPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TotalPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.DiscountPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TaxRate" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TaxUnitPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TaxPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TotalTaxPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.Remark" />
        <Select @bind-Value="@Model.LinkedVM.WarehouseId" Items="AllWarehouses" Id="gc76a1fb8bd3546a9879002e592b21de4" />
    </Row>

    <div class="modal-footer table-modal-footer">
        <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
        <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
    </div>

</ValidateForm>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private BuyDetailBatchVM Model = new BuyDetailBatchVM();
    private ValidateForm vform { get; set; }

    private async Task Submit(EditContext context)
    {
        Model.Ids = ids;
        await PostsForm(vform, "/api/Po/BuyDetail/BatchEdit", (s) => WtmBlazor.Localizer["Sys.BatchEditSuccess", s], method: HttpMethodEnum.POST);
    }


    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllBuys = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    private List<SelectedItem> AllWarehouses = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllBuys = await WtmBlazor.Api.CallItemsApi("/api/Po/BuyDetail/GetBuys");
        AllBuys.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/Po/BuyDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Po/BuyDetail/GetWarehouses");
        AllWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });

        await base.OnInitializedAsync();
    }
}
